from django.contrib.auth.models import User
from django.db import models


class BaseModel(models.Model):
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    last_modified = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        abstract = True


# Create your models here.
# 农户档案模型类
class FarmerFile(BaseModel):
    gender_choice = (
        (0, '女'),
        (1, '男'),
    )
    status_choice = (
        (0, '待审核'),
        (1, '审核通过'),
        (-1, '审核未通过'),
    )

    name = models.CharField(max_length=50, verbose_name='姓名')
    gender = models.IntegerField(choices=gender_choice, verbose_name='性别')
    age = models.IntegerField(verbose_name='年龄')
    phone = models.CharField(max_length=11, verbose_name='电话')
    address = models.CharField(max_length=200, verbose_name='地址')
    id_number = models.CharField(max_length=18, unique=True, verbose_name='身份证号码')
    status = models.IntegerField(choices=status_choice, default=0, verbose_name='状态')
    loan_limit = models.IntegerField(default=0, verbose_name='贷款限额')

    # 农户
    farmer = models.OneToOneField(to=User, related_name='farmer_id', on_delete=models.CASCADE, null=True,
                                  verbose_name='关联农户')
    # 银行客户经理
    staff = models.ForeignKey(to=User, related_name='staff_id', on_delete=models.CASCADE, null=True,
                              verbose_name='审核人')

    class Meta:
        verbose_name = '农户档案'
        verbose_name_plural = '农户档案'

    def __str__(self):
        return self.name
